<?
header("content-type:text/html;charset:utf-8;");
$mysqli=new mysqli("localhost","root","bs!@135","weekus");
$name=$_POST['username'];  //用户名
$password=md5($_POST['password']);//密码
$result=mysqli_query($mysqli,"select  *  from  z_admin  where  username='$name'  and password='$password' ")  ;
/*
if(!$result){
  echo("mysqli error");
}*/
//判断账号密码是否正确
//如果正确

if(mysqli_num_rows($result)==1){

       echo "name  password true";
       echo"<br>";
        $row = mysqli_fetch_array($result);
        $_SESSION['user_id']=$row['user_id'];
        $_SESSION['username']=$row['username'];
        $_SESSION['password']=$row['password'];
        $_SESSION['aorb']=1;//  登录成功之后赋值aorb等于1  然后登录的时候判断是否存在这个值等于1
        header('Location:/cj/admin.php ');
    /* echo $_SESSION[aorb];

     var_dump($_SESSION);
      print_r($_SESSION);*/
      }
      else{//若查到的记录不对，则设置错误信息

        echo"Sorry, you must enter a valid username and password to log in.";
     //   $error_msg = 'Sorry, you must enter a valid username and password to log in.';
      }


mysqli_close($mysqli);

?>
